<?php
namespace app\custom_user\controller;

use app\custom_user\logic\UserLogic;
use app\custom_user\model\UserSession;

class IndexController extends UserBaseController
{
    public function index()
    {
        $user=$this->checkLogin();
        $this->assign("user",$user);
        return $this->fetch("index");
    }
    //退出登录
    public function logout()
    {
        UserSession::clear();
        $this->success("退出成功",url("login"));
    }
    public function updateInfo()
    {
        $user=$this->checkLogin();
        $this->assign("user",$user);
        return $this->fetch("updateInfo");
    }
    public function doUpdateInfo()
    {
        $user=$this->checkLogin();
        $ul=new UserLogic();
        $user=$ul->updateInfo($user,$_REQUEST);
        if(!$user){
            $this->error($ul->getError());
        }
        $this->success("修改成功",url("index"));
    }
    public function updatePassword()
    {
        return $this->fetch("updatePassword");
    }
    public function doUpdatePassword()
    {
        $user=$this->checkLogin();
        $ul=new UserLogic;
        $result=$ul->updatePassword($user,$_REQUEST);
        if(!$result){
            $this->error($ul->getError());
        }
        $this->success("修改成功",url("index"));
    }
    public function updateMobile()
    {
        return $this->fetch("updateMobile");
    }
    public function doUpdateMobile()
    {
        $user=$this->checkLogin();
        $ul=new UserLogic;
        $result=$ul->updateMobile($user,$_REQUEST);
        if(!$result){
            $this->error($ul->getError());
        }
        $this->success("修改成功",url("index"));
    }
    public function getbackPassword()
    {
        return $this->fetch("getbackPassword");
    }
    public function doGetbackPassword()
    {
        $ul=new UserLogic;
        $result=$ul->getbackPassword($_REQUEST);
        if(!$result){
            $this->error($ul->getError());
        }
        $this->success("修改成功",url("login"));
    }
}
